#include "FI_RepoFixingData.h"
#include <msgcenter/FIMsgProcess.h>
#include <qbkernel/include/qb_base.h>
#include <qbprotocol/include/rdProto.h>
#include <qbprotocol/include/SSFIModel.h>
#include <qbtools/message/MessagePoster.h>

FIRepoFixingData::FIRepoFixingData()
{
	m_vctOrder = { "FR001", "FR007", "FR014" };
	clear();
}

void FIRepoFixingData::clear()
{
	m_dataList.m_List.clear();
	m_dataList.m_List.push_back(xBaseUnit_c("FR001", "CMB1D00120", "", 0.00000, 0.00000));
	m_dataList.m_List.push_back(xBaseUnit_c("FR007", "CMB1D00121", "", 0.00000, 0.00000));
	m_dataList.m_List.push_back(xBaseUnit_c("FR014", "CMB1D00122", "", 0.00000, 0.00000));
}

const std::vector<std::string>& FIRepoFixingData::getOrder()
{
	return m_vctOrder;
}

const xFixingRepoRateList_c& FIRepoFixingData::getData()
{
	return m_dataList;
}

void FIRepoFixingData::reqData(MessageReceiver* msgRecv)
{
	static bool reqOnce = false;
	if (reqOnce)return;
	reqOnce = true;

	qb::SSRequestMsg msg;
	msg.m_pRequest = nullptr;
	msg.m_FuncID = E_FID_QB_FIXIN_REPO_RATE_QUERY;
	MessagePoster poster(&msg, qbmsg::fixedincome::EncodeFunc);
	poster.send(msgRecv);

	PushMsgInfo pmi3(E_FID_QB_FIXIN_REPO_RATE_PUSH, "", nullptr);
	msg.m_FuncID = E_FID_QB_FIXIN_REPO_RATE_PUSH;
	msgRecv->registPush(pmi3, &msg, qbmsg::fixedincome::EncodeFunc);
}

bool FIRepoFixingData::onReceive(int32_t funcId, const qb::SSAckMsg& msg)
{
	if (funcId != E_FID_QB_FIXIN_REPO_RATE_QUERY && funcId != E_FID_QB_FIXIN_REPO_RATE_PUSH)return false;

	SCOPED_MUTEX(m_lock);
	clear();
	const xFixingRepoRateList_c* pdata = (xFixingRepoRateList_c*)msg.m_pRet;
	if (!pdata)return false;

	m_dataList.m_List = pdata->m_List;
	return true;
}
